package org.example.demo3.config;

import org.example.demo3.enums.ProductTypeEnum;
import org.springframework.core.convert.converter.Converter;


import java.util.Set;

/**
 * 作者:xuSen
 * 日期2025/3/14 16:53
 */
//public class StringToProductConditionConverter implements Converter<String, ProductConditionEnum>
public class StringToProductTypeConverter implements Converter<String, ProductTypeEnum> {
    @Override
    public ProductTypeEnum convert(String source) {
        try {
            int code = Integer.parseInt(source);
            return ProductTypeEnum.fromCode(code);
        } catch (NumberFormatException e) {
            // 修改为分类类型错误提示
            throw new IllegalArgumentException("分类类型参数必须是数字");
        }
    }
}

